<template>
<div>
    <!-- 面包屑 -->
    <a-breadcrumb style="margin: 16px 0">
        <a-breadcrumb-item>Users</a-breadcrumb-item>
        <a-breadcrumb-item>Blog</a-breadcrumb-item>
        <a-breadcrumb-item><a @click='tohome'>home</a></a-breadcrumb-item>
        <a-breadcrumb-item>userManage</a-breadcrumb-item>
    </a-breadcrumb>
    <a-table :columns="columns" :data-source="data">
    <a slot="action" slot-scope="text" href="javascript:;"></a>
    <span slot="action" slot-scope="text">
        <a @click="prohibit(text.email,text.status)">封禁</a>
        <a-divider type="vertical" />
        <a @click="unseal(text.email,text.status)">解封</a>
    </span>
  </a-table>
</div>

</template>
<script>
const columns = [
  { title: '编号', dataIndex: 'number', key: 'number' },
  { title: '用户名', dataIndex: 'email', key: 'email' },
  { title: '昵称', dataIndex: 'nickName', key: 'nickName' },
  { title: '状态', dataIndex: 'status', key: 'status' },
  { title: '操作', dataIndex: '', key: 'x', scopedSlots: { customRender: 'action'},},
];

const data = [
  {
    key: 1,
    number: 1,
    email: '1831330711@qq.com',
    name: '阿蛋',
    status:'封禁中'
  },
    {
    key: 2,
    number: 2,
    email: '212112@7k7k.com',
    name: '胡建鸣',
    status:'封禁中'
  },
    {
    key: 3,
    number: 3,
    email: '24587887211@qq.com',
    name: '曹起灵',
    status:'正常'
  },
    {
    key: 4,
    number: 4,
    email: '22772201@163.com',
    name: '赫鲁晓夫',
    status:'正常'
  },
];

export default {
  data() {
    return {
      data,
      columns,
    };
  },
  created () {
        this.show()
      },
  methods:{
      tohome(){
          this.$router.push('/manage/home')
          window.sessionStorage.setItem('activepath','/manage/home')
      },   
    //   tomodify(){
    //       this.$router.push('/modify')
    //   },
    //   browser(){
    //       this.$router.push('/look')
    //   }
    async prohibit(email,status){
        if(status=='正常')
        {
          var s = 1
        const{data:res} = await this.$http.get('http://localhost:8081/user/changestatus',{params:{email:email,status:s}})
        if(res.code == 200){
          this.$message.success('封禁成功')
          this.show()}
          else{
            this.$message.error('封禁失败')
          }
        }
        else this.$message.warning('该用户已处于封禁状态')
    },
    async unseal(email,status){
         if(status=='封禁中')
        {
          var s = 0
        const{data:res} = await this.$http.get('http://localhost:8081/user/changestatus',{params:{email:email,status:s}})
        if(res.code == 200){
          this.$message.success('解封成功')
          this.show()}
          else{
            this.$message.error('解封失败')
          }
       
        }
        else this.$message.warning('该用户已处于正常状态')
    },
    async show(){
        const {data:res} = await this.$http.get('http://localhost:8081/user/selectalluser')
        this.data = res.data
        for(var i=0;i<this.data.length;i++){
          this.data[i].number=i+1;
          if(this.data[i].status==0){
            this.data[i].status='正常'
          }
          else{
            this.data[i].status='封禁中'
          }
        }
    }
  }
};
</script>